package com.qtummatrix.service.impl;

import com.qtummatrix.dao.ILoansDao;
import com.qtummatrix.entity.*;
import com.qtummatrix.service.ILoansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * create by Gongshiyong  2019-12-07 11:31
 */
@Service("loansService")
public class LoansServiceImpl implements ILoansService {
    @Autowired
    @Qualifier("loansDao")
    private ILoansDao iLoansDao;

    /**
     * 查询产品详情
     */
    @Override
    public LoanproductsEntity show(int id) {
        LoanproductsEntity loanproductsEntity = iLoansDao.particular(id);
        return loanproductsEntity;
    }

    /**
     * 我的贷款
     *
     * @param name 客户名称
     * @param UID  身份证号
     */
    @Override
    public String loginLoans(String name, String UID) {
        return iLoansDao.login(name, UID);
    }

    /**
     * 客户信息
     *
     * @param name
     * @param UID
     * @return
     */
    @Override
    public CustomerinfoEntity getMessage(String name, String UID) {
        CustomerinfoEntity customerinfoEntity = iLoansDao.getMessage(name, UID);
        return customerinfoEntity;
    }

    /**
     * 贷款信息
     *
     * @param username
     * @return
     */
    @Override
    public ContractEntity getShow(String username) {
        ContractEntity contractEntity = iLoansDao.showMessage(username);
        return contractEntity;
    }

    @Override
    public String addUsers(ApplicationEntity applicationEntity) {
        String str = iLoansDao.showUser(applicationEntity);
        if (str.equals("用户不存在！")) {
            str = iLoansDao.queryUser(applicationEntity);
            if (str.equals("用户不存在！")) {
                iLoansDao.addUser(applicationEntity);
                CustomerinfoEntity customerinfoEntity = new CustomerinfoEntity();
                customerinfoEntity.setCustomername(applicationEntity.getCustomename());
                customerinfoEntity.setUid(applicationEntity.getCustomeuid());
                customerinfoEntity.setTel(applicationEntity.getCustomephone());
                addInfo(customerinfoEntity);
            }
        }
        return str;
    }

    @Override
    public String addInfo(CustomerinfoEntity customerinfoEntity) {
        String str = iLoansDao.getBlack(customerinfoEntity);
        if (str == "用户不存在！") {
            str = iLoansDao.getInfos(customerinfoEntity);
            if (str == "客户表中，用户不存在！") {
                iLoansDao.addInfos(customerinfoEntity);
            }
        }
        return str;
    }

    /**
     * 查询模组
     *
     * @return
     */
    @Override
    public List<QuestionsEntity> getQuest() {
        List<Integer> list = iLoansDao.question();
        List<QuestionsEntity> list1 = iLoansDao.getQuestr(list);
        return list1;
    }

    @Override
    public String getGrode1(String[] arr, String username) {
        List<Integer> list = iLoansDao.question();
        int sum = iLoansDao.getGrode(arr, list);
        String str = iLoansDao.getRate(sum);
        iLoansDao.addInfo(str, username);
        return str;
    }
}
